<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div style="float: right;margin-right: 17px;margin-top: 15px;">
        <el-button type="primary" size="mini" @click="addSubjectOpinion()">新增征求意见</el-button>
      </div>
      <div style="margin-top: 15px">
        <span style="font-weight: 600;margin-left: 10px;">征求意见结果列表</span>
      </div>
      <div class="card-body">
        <avue-crud :data="subjectOpinionListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @on-load="getResultList"
                   @refresh-change="refreshChange"
                   @search-change="searchChange"
                   class="avuecrud">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="feedBackSummary(scope.row,scope.index)">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">查看反馈</p>
            </div>
            <div class="menu-title" @click.stop="subjectOpinionDelete(scope.row,scope.index)">
              <i class="iconfont iconalter icon-warning"></i>
              <p class="menu-title-text">删除</p>
            </div>
          </template>
        </avue-crud>
      </div>
    </div>
  </basic-container>
</template>

<script>
  import {subjectOpinionDelete, getSubjectOpinionList} from "@/api/subject";

  export default {
    name: "subjectOpinionList",
    created() {

    },
    data() {
      return {
        headerData: {
          title: '课题征求意见'
        },
        subjectOpinionListData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth: 220,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "发起征求意见部门",
              width: 250,
              prop: "nickname",
              cell: true
            },
            {
              label: "征求意见名称",
              width: 330,
              prop: "title",
              cell: true
            },
            {
              label: "发起时课题状态",
              width: 180,
              prop: "type",
              cell: true,
              dicData: [
                {
                  label: "拟定",
                  value: "0"
                },
                {
                  label: "已列入计划",
                  value: "1"
                },
              ],
            },
          ]
        },
        tableLoading: false,
      }
    },
    methods: {
      // 课题详情跳转
      feedBackSummary(row) {
        let src = `/feedBackSummary/detail/${row.opinionId}`;
        this.$router.push({
          path: src
        })
      },
      subjectOpinionDelete(row) {
        this.$confirm("确定删除此征求意见吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          subjectOpinionDelete(row.opinionId).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(0);
            }
          })
        })
      },
      searchChange() {

      },
      refreshChange() {

      },
      getResultList(page) {
        getSubjectOpinionList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          subjectId: this.$route.params.id,
        })).then(response => {
          this.subjectOpinionListData = response.data.data.records;
        })
      },
      // 发起课题征集跳转
      addSubjectOpinion() {
        let src = `/addSubjectOpinion/detail/${this.$route.params.id}`;
        this.$router.push({
          path: src
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .card-body {
    padding: 10px;
    min-height: 400px
  }
</style>
